{% extends 'base/admin_base.html' %}

{% block hedaer %}
  新闻管理列表
{% endblock %}

{% block title %}
  新闻管理列表
{% endblock %}

{% block content %}
  <style>
    .ml20 {
      margin-left: 20px;
    }

    .mt20 {
      margin-top: 20px;
    }
  </style>
  <div class="box">
    <div class="box header" style="margin: 0;">
      <form action="" class="form-inline">
        <div class="form-group ml20 mt20">
          <label for="select-time">时间：</label>
          {% if start_time %}

            <input type="text" class="form-control" placeholder="请选择起始时间" readonly id="select-time" name="start_time"
                   value="{{ start_time }}">
          {% else %}
            <input type="text" class="form-control" placeholder="请选择起始时间" readonly id="select-time" name="start_time">
          {% endif %}

          -
          {% if end_time %}
            <input type="text" class="form-control" placeholder="请选择结束时间" readonly name="end_time"
                   value="{{ end_time }}">
          {% else %}
            <input type="text" class="form-control" placeholder="请选择结束时间" readonly name="end_time">
          {% endif %}

        </div>
        <div class="form-group ml20 mt20">
          <label for="title">标题：</label>
          {% if title %}
            <input type="text" class="form-control" placeholder="请输入标题" id="title" name="title" value="{{ title }}">
          {% else %}
            <input type="text" class="form-control" placeholder="请输入标题" id="title" name="title">
          {% endif %}

        </div>
        <div class="form-group ml20 mt20">
          <label for="author">作者：</label>
          {% if author %}
            <input type="text" class="form-control" placeholder="请输入作者" id="author" name="author" value="{{ author }}">
          {% else %}
            <input type="text" class="form-control" placeholder="请输入作者" id="author" name="author">
          {% endif %}

        </div>
        <div class="form-group ml20 mt20">
          <label for="tag">标签：</label>
          <select class="form-control" id="tag" name="tag_id">
            <option value="0">--请选择标签--</option>
            {% for tag in tags %}
              {% if tag_id == tag.id %}
                <option value="{{ tag.id }}" selected>{{ tag.name }}</option>
              {% else %}
                <option value="{{ tag.id }}">{{ tag.name }}</option>
              {% endif %}
            {% endfor %}

          </select>
        </div>
        <div class="form-group ml20 mt20">
          <button class="btn btn-primary">查询</button>
          <a href="{% url 'admin:news_list' %}" class="btn btn-info ml20">清除查询</a>
        </div>
      </form>
    </div>
    <div class="box-body">
      <table class="table table-bordered table-hover">
        <thead>
        <tr>
          <th>标题</th>
          <th>作者</th>
          <th>标签</th>
          <th>发布时间</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for news in newses %}
          <tr>
            <td><a href="javascript:void(0);" target="_blank">{{ news.title }}</a></td>
            <td>{{ news.author.username }}</td>
            <td>{{ news.tag.name }}</td>
            <td>{{ news.pub_time|date:"Y年m月d日  H:i:s" }}</td>
            <td>
              <a href="javascript:void(0);" class="btn btn-xs btn-warning">编辑</a>
              <a href="javascript:void (0);" class="btn btn-xs btn-danger btn-del" data-news-id="{{ news.id }}">删除</a>
            </td>
          </tr>
        {% endfor %}

        </tbody>
      </table>
    </div>
    <div class="box-footer">
      <span class="pull-left">第3页/总共10页</span>
      <nav class="pull-right">
        <!-- 分页 -->
        <ul class="pagination">
          <!-- 上一页 -->
          {% if page.has_previous %}
{#            # ?p=1&start_time=2018%2F09%2F07&end_time=2018%2F09%2F09&title=&author=&tag_id=0#}
{#            # ?p=1&{"start_time":2018, }#}
            <li><a href="?p={{ page.previous_page_number }}&{{ other_param }}">上一页</a></li>
          {% else %}
            <li class="disabled"><a href="javascript:void(0);">上一页</a></li>
          {% endif %}

          {#        {% for page_num in paginator.page_range %}#}
          {#          {% if page.number == page_num %}#}
          {#          <li class="active">#}
          {#            {% else %}#}
          {#            <li>#}
          {#          {% endif %}#}
          {#          <a href="?p={{ page_num }}">{{ page_num }}</a></li>#}
          {#        {% endfor %}#}



          {% if left_has_more %}
            <li><a href="?p=1&{{ other_param }}">1</a></li>
            <li><a href="javascript:void(0)">...</a></li>
          {% endif %}

          {% for page in left_pages %}
            <li><a href="?p={{ page }}&{{ other_param }}">{{ page }}</a></li>
          {% endfor %}


          {% if current_page %}
            <li class="active"><a href="?p={{ current_page }}&{{ other_param }}">{{ current_page }}</a></li>
          {% endif %}

          {% for page in right_pages %}
            <li><a href="?p={{ page }}&{{ other_param }}">{{ page }}</a></li>
          {% endfor %}

          {% if right_has_more %}
            <li><a href="javascript:void(0)">...</a></li>
            <li><a href="?p={{ total_page }}&{{ other_param }}">{{ total_page }}</a></li>
          {% endif %}


          <!-- 下一页 -->
          {% if page.has_next %}
            <li><a href="?p={{ page.next_page_number }}&{{ other_param }}">下一页</a></li>
          {% else %}
            <li class="disabled"><a href="javascript:void(0);">下一页</a></li>
          {% endif %}

        </ul>
      </nav>
    </div>
  </div>
{% endblock %}

{% block srcipt %}
  <script src="/static/js/admin/news/news_list.js"></script>
{% endblock %}